package com.jilefojing.beans.pojos.enhanced;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.Date;

import com.jilefojing.beans.enums.ItemTypeEnumForSource;
import com.jilefojing.beans.enums.PlatformEnumForPublish;
import com.jilefojing.beans.enums.ProgressStatusForSource;
import com.jilefojing.beans.enums.StatusEnumForPublish;
import com.jilefojing.beans.pojos.Recommend;
import com.jilefojing.beans.pojos.enhanced.base.BaseEnhanced;

/**
 * 
 * @author 作者 jgshun
 * @date 创建时间 2016年07月19日 17时57分48秒
 */
public class EnhancedRecommend extends BaseEnhanced {
	public EnhancedRecommend(Recommend recommend) {
		// TODO 自动生成 细微误差自己调整
		if (recommend.getId() != null) {
			this.id = recommend.getId();
		}
		if (recommend.getItemType() != null) {
			this.itemType = ItemTypeEnumForSource.getItemTypeEnumByCode(recommend.getItemType());
		}
		if (recommend.getStatus() != null) {
			this.status = StatusEnumForPublish.getStatusEnumByCode(recommend.getStatus());
		}
		this.createTime = recommend.getCreateTime();
		this.startTime = recommend.getStartTime();
		this.endTime = recommend.getEndTime();
		if (recommend.getCreateUser() != null) {
			EnhancedUser enhancedUser = new EnhancedUser();
			enhancedUser.setId(recommend.getCreateUser());
			this.enhancedUser = enhancedUser;
		}
		this.updateTime = recommend.getUpdateTime();
		if (recommend.getItemId() != null && this.itemType != null) {
			try {
				Class<? extends BaseEnhanced> _EnhancedClass = this.itemType.getEnhancedItemClass();
				BaseEnhanced _EnhancedItem = _EnhancedClass.newInstance();
				for (Method _Method : _EnhancedClass.getDeclaredMethods()) {
					if (_Method.getName().equals("setId")) {
						_Method.invoke(_EnhancedItem, recommend.getItemId());
						break;
					}
				}
				this.enhancedItem = _EnhancedItem;
			} catch (SecurityException e) {
				e.printStackTrace();
			} catch (IllegalArgumentException e) {
				e.printStackTrace();
			} catch (InvocationTargetException e) {
				e.printStackTrace();
			} catch (InstantiationException e) {
				e.printStackTrace();
			} catch (IllegalAccessException e) {
				e.printStackTrace();
			}
		}
		if (recommend.getPlatform() != null) {
			this.platform = PlatformEnumForPublish.getPlatformEnumByCode(recommend.getPlatform());
		}
		this.coverUrl = recommend.getCoverUrl();
		this.setInfo(recommend.getInfo());
		if (recommend.getSort() != null) {
			this.sort = recommend.getSort();
		}

		if (recommend.getProgressStatus() != null) {
			this.setProgressStatus(ProgressStatusForSource.getProgressStatusEnumByCode(recommend.getProgressStatus()));
		}
	}

	private long id;
	private StatusEnumForPublish status;
	private Date createTime;
	private Date startTime;
	private Date endTime;
	private EnhancedUser enhancedUser;
	private Date updateTime;
	private ItemTypeEnumForSource itemType;
	private BaseEnhanced enhancedItem;
	private PlatformEnumForPublish platform;
	private String coverUrl;
	private String info;
	private double sort;
	private ProgressStatusForSource progressStatus;

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}

	public ItemTypeEnumForSource getItemType() {
		return itemType;
	}

	public void setItemType(ItemTypeEnumForSource itemType) {
		this.itemType = itemType;
	}

	public StatusEnumForPublish getStatus() {
		return status;
	}

	public void setStatus(StatusEnumForPublish status) {
		this.status = status;
	}

	public PlatformEnumForPublish getPlatform() {
		return platform;
	}

	public void setPlatform(PlatformEnumForPublish platform) {
		this.platform = platform;
	}

	public EnhancedRecommend() {
	}

	public Date getCreateTime() {
		return createTime;
	}

	public void setCreateTime(Date createTime) {
		this.createTime = createTime;
	}

	public Date getStartTime() {
		return startTime;
	}

	public void setStartTime(Date startTime) {
		this.startTime = startTime;
	}

	public Date getEndTime() {
		return endTime;
	}

	public void setEndTime(Date endTime) {
		this.endTime = endTime;
	}

	public EnhancedUser getEnhancedUser() {
		return enhancedUser;
	}

	public void setEnhancedUser(EnhancedUser enhancedUser) {
		this.enhancedUser = enhancedUser;
	}

	public Date getUpdateTime() {
		return updateTime;
	}

	public void setUpdateTime(Date updateTime) {
		this.updateTime = updateTime;
	}

	public BaseEnhanced getEnhancedItem() {
		return enhancedItem;
	}

	public void setEnhancedItem(BaseEnhanced enhancedItem) {
		this.enhancedItem = enhancedItem;
	}

	public String getCoverUrl() {
		return coverUrl;
	}

	public void setCoverUrl(String coverUrl) {
		this.coverUrl = coverUrl;
	}

	public String getInfo() {
		return info;
	}

	public void setInfo(String info) {
		this.info = info;
	}

	public double getSort() {
		return sort;
	}

	public void setSort(double sort) {
		this.sort = sort;
	}

	public ProgressStatusForSource getProgressStatus() {
		return progressStatus;
	}

	public void setProgressStatus(ProgressStatusForSource progressStatus) {
		this.progressStatus = progressStatus;
	}

}